import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemigo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Enemigo extends Actor
{
    private int resistencia;
    private int x0;
    private int x1;
    private boolean explota=false;
    private boolean vivo=true;
    private boolean especial;
    private int nivel;
    /**
     * Act - do whatever the Enemigo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Enemigo(int res,int i, int f, int n)
    {
        nivel=n;
        especial=false;
        resistencia=res;
        x0=i;
        x1=f;
    }
    public Enemigo(int res)
    {
        especial=true;
        resistencia=res;
    }
    public void act() 
    {
        if(((FlagWarWorld)getWorld()).getJugador())
        {
        if(checkCollision())
        {
            this.setResistencia();
            if(explota==true)
             getWorld().addObject(new Explosion(),getX(),getY());
            if(resistencia==0 || vivo==false)
            {
                ((FlagWarWorld)getWorld()).menosEnemigos();
                ((FlagWarWorld)getWorld()).generaBonos();
                
                if(especial)
                {
                    //getWorld().addObject(new Bandera(),956,77);
                }
                getWorld().removeObject(this);
            }
        }
    }
        // Add your action code here.
    }    
    
    public void setResistencia()
    {
        resistencia--;
        //System.out.println(resistencia);
    }
    public int getResistencia()
    {
        return resistencia;
    }
      public boolean checkCollision()
    {
         PlayerShot bala = (PlayerShot)getOneIntersectingObject(PlayerShot.class);  
        if (bala != null)
        {
            int tipo = bala.getTipoBala();
            if(tipo==3)
            {
                explota=true;
                //if(especial=false)
                vivo=false;
            }
            else
            {   if(resistencia>1)
                getWorld().addObject(new Sangre(),getX(),getY());
            }
            getWorld().removeObject(getOneIntersectingObject (PlayerShot.class));
            
         return true;   
        }
        
        else
        return false;
    }
    public boolean Limite()
    {
        if(getX()<x0 || getX()>x1)
        { return true;
        }
        else{return false;
        }
    }
    
    public int getNivel()
    {
        return nivel;
    }
}
